package su.jet.irc;



import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import su.jet.common.irc.domain.User;
import su.jet.irc.server.domain.ChatServer;

public class UsersReg {

public static void main(String[] args) {
		
		List<User> users = new ArrayList<User>();
		users.add(new User("vasya", "vasya"));
		users.add(new User("petya", "petya"));
		users.add(new User("klava", "klava"));
		
		System.out.println(saveRegisteredUsers());
	}
	
	public static  boolean saveRegisteredUsers() {
		try {
			Set<User> savedUsers = new HashSet<User>();
			User user = new User("vasya", "vasya");
			User user2 = new User("petya", "petya");
			User user3 = new User("klava", "klava");
			savedUsers.add(user);
			savedUsers.add(user2);
			savedUsers.add(user3);
			FileOutputStream fileOutputStream = new FileOutputStream(ChatServer.DATA_FILE_PATH);
			ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
			objectOutputStream.writeObject(savedUsers);
			objectOutputStream.close();
			fileOutputStream.close();
		} catch (FileNotFoundException fnfe) {
			fnfe.printStackTrace();
			return false;
		} catch (IOException ioe) {
			ioe.printStackTrace();
			return false;
		}
		return true;
	}

}
